#include "XDisplay.h"

XDisplay::~XDisplay() {
	XCloseDisplay(this->display_);
}


Atom XDisplay::getAtom(const string& name) const{
	Atom a = XInternAtom(display_, name.c_str(), True);
	assert(a != None);
	return a;	
}

std::string * XDisplay::getWindowProperty(Window window, Atom property) {
	static const int maxPropertyLength = 1024;
	Atom returnedType;
	int returnedFormat;
	unsigned char *data;
	unsigned long bytesLeft, itemsReturned;
	std::string *result;
	XGetWindowProperty (display_, window, property,
		0, maxPropertyLength, False, AnyPropertyType,  
		&returnedType, &returnedFormat,	
		&itemsReturned, &bytesLeft,
		&data);
	if (itemsReturned < 1 || returnedType == None ) {
		result = new std::string("");
	} else {
		result = new std::string((const char*)data);
	}
	if (data!=NULL) {
		XFree(data);
	}
	return result;
}


